package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.constant.EmpChangeStatus;
import org.jsola.hr.constant.EmpChangeType;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.core.example.BaseExample.*;
import static org.jsola.hr.example.EmpChangesExample.*;

/**
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpChangesQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = "名字")
    private String empName;

    @ApiParam(value = "标签")
    private String tag;

    @ApiParam(value = "工作性质")
    private Integer postType;

    @ApiParam(value = N_EMP_ID, example = E_EMP_ID)
    @Length(max = 32)
    private String empId;

    @ApiParam(value = N_APPRO_FLOW_ID, example = E_APPRO_FLOW_ID)
    @Length(max = 32)
    private String approFlowId;

    @ApiParam(value = N_USER_APPRO_FLOW_ID, example = E_USER_APPRO_FLOW_ID)
    @Length(max = 32)
    private String userApproFlowId;

    @ApiParam(value = N_CHANGE_TYPE, example = E_CHANGE_TYPE, allowableValues = EmpChangeType.VALUES_STR)
    private Integer changeType;

    @ApiParam(value = N_PRE_CODE, example = E_PRE_CODE)
    @Length(max = 255)
    private String preCode;

    @ApiParam(value = N_CURRENT_CODE, example = E_CURRENT_CODE)
    @Length(max = 255)
    private String currentCode;

    /**
     * 转正式时间查询范围
     */
    @ApiParam(value = N_FORMALLY_DATE_START, example = E_FORMALLY_DATE_START)
    private Date formallyDateStart;
    @ApiParam(value = N_FORMALLY_DATE_END, example = E_FORMALLY_DATE_END)
    private Date formallyDateEnd;


    /**
     * 试用期转正时间查询范围
     */
    @ApiParam(value = N_PROBATION_DATE_START, example = E_PROBATION_DATE_START)
    private Date probationDateStart;
    @ApiParam(value = N_PROBATION_DATE_END, example = E_PROBATION_DATE_END)
    private Date probationDateEnd;


    /**
     * 转正时间查询范围
     */
    @ApiParam(value = N_REGULAR_DATE_START, example = E_REGULAR_DATE_START)
    private Date regularDateStart;
    @ApiParam(value = N_REGULAR_DATE_END, example = E_REGULAR_DATE_END)
    private Date regularDateEnd;


    @ApiParam(value = N_REGULAR_EVALUATION, example = E_REGULAR_EVALUATION)
    @Length(max = 2000)
    private String regularEvaluation;

    @ApiParam(value = N_REGULAR_ATTACMENT, example = E_REGULAR_ATTACMENT)
    @Length(max = 32)
    private String regularAttacment;

    /**
     * 调岗时间查询范围
     */
    @ApiParam(value = N_ADJUSTMENT_DATE_START, example = E_ADJUSTMENT_DATE_START)
    private Date adjustmentDateStart;
    @ApiParam(value = N_ADJUSTMENT_DATE_END, example = E_ADJUSTMENT_DATE_END)
    private Date adjustmentDateEnd;


    @ApiParam(value = N_ADJUSTMENT_REASON, example = E_ADJUSTMENT_REASON)
    @Length(max = 255)
    private String adjustmentReason;

    @ApiParam(value = N_ADJUSTMENT_ATTACHMENT, example = E_ADJUSTMENT_ATTACHMENT)
    @Length(max = 32)
    private String adjustmentAttachment;

    @ApiParam(value = N_PRE_DEP, example = E_PRE_DEP)
    @Length(max = 10000)
    private String preDep;

    @ApiParam(value = N_PRE_POSITION, example = E_PRE_POSITION)
    @Length(max = 10000)
    private String prePosition;

    @ApiParam(value = N_PRE_LEVEL, example = E_PRE_LEVEL)
    private Integer preLevel;

    @ApiParam(value = N_PRE_SUPERVISOR, example = E_PRE_SUPERVISOR)
    @Length(max = 255)
    private String preSupervisor;

    @ApiParam(value = N_PRE_MANAGER_FORM, example = E_PRE_MANAGER_FORM)
    private Integer preManagerForm;

    @ApiParam(value = N_PRE_WORK_CITY_ID, example = E_PRE_WORK_CITY_ID)
    @Length(max = 255)
    private String preWorkCityId;

    @ApiParam(value = N_CURRENT_DEP, example = E_CURRENT_DEP)
    @Length(max = 255)
    private String currentDep;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_CURRENT_POSITION, example = E_CURRENT_POSITION)
    @Length(max = 255)
    private String currentPosition;

    @ApiParam(value = N_CURRENT_LEVEL, example = E_CURRENT_LEVEL)
    private Integer currentLevel;

    @ApiParam(value = N_CURRENT_SUPERVISOR, example = E_CURRENT_SUPERVISOR)
    @Length(max = 255)
    private String currentSupervisor;

    @ApiParam(value = N_CURRENT_MANAGER_FORM, example = E_CURRENT_MANAGER_FORM)
    private Integer currentManagerForm;

    @ApiParam(value = N_CURRENT_WORK_CITY_ID, example = E_CURRENT_WORK_CITY_ID)
    @Length(max = 255)
    private String currentWorkCityId;

    @ApiParam(value = N_QUIT_TYPE, example = E_QUIT_TYPE)
    private Integer quitType;

    /**
     * 离职时间查询范围
     */
    @ApiParam(value = N_QUIT_DATE_START, example = E_QUIT_DATE_START)
    private Date quitDateStart;
    @ApiParam(value = N_QUIT_DATE_END, example = E_QUIT_DATE_END)
    private Date quitDateEnd;


    /**
     * 预计离职时间查询范围
     */
    @ApiParam(value = N_PRE_QUIT_DATE_START, example = E_PRE_QUIT_DATE_START)
    private Date preQuitDateStart;
    @ApiParam(value = N_PRE_QUIT_DATE_END, example = E_PRE_QUIT_DATE_END)
    private Date preQuitDateEnd;


    /**
     * 办理离职时间查询范围
     */
    @ApiParam(value = N_HANDLE_QUIT_DATE_START, example = E_HANDLE_QUIT_DATE_START)
    private Date handleQuitDateStart;
    @ApiParam(value = N_HANDLE_QUIT_DATE_END, example = E_HANDLE_QUIT_DATE_END)
    private Date handleQuitDateEnd;


    @ApiParam(value = N_PERSONAL_REASON, example = E_PERSONAL_REASON)
    private Integer personalReason;

    @ApiParam(value = N_COMPANY_REASON, example = E_COMPANY_REASON)
    private Integer companyReason;

    @ApiParam(value = N_QUIT_REASON, example = E_QUIT_REASON)
    @Length(max = 2000)
    private String quitReason;

    @ApiParam(value = N_QUIT_REMARKS, example = E_QUIT_REMARKS)
    @Length(max = 2000)
    private String quitRemarks;

    @ApiParam(value = N_APPLY_QUIT_REASON, example = E_APPLY_QUIT_REASON)
    @Length(max = 2000)
    private String applyQuitReason;

    /**
     * 补偿金查询范围
     */
    @ApiParam(value = N_COMPENSATION_START, example = E_COMPENSATION_START)
    private Integer compensationStart;
    @ApiParam(value = N_COMPENSATION_END, example = E_COMPENSATION_END)
    private Integer compensationEnd;


    /**
     * 代通知金查询范围
     */
    @ApiParam(value = N_PAYMENT_LIEU_NOTICE_START, example = E_PAYMENT_LIEU_NOTICE_START)
    private Integer paymentLieuNoticeStart;
    @ApiParam(value = N_PAYMENT_LIEU_NOTICE_END, example = E_PAYMENT_LIEU_NOTICE_END)
    private Integer paymentLieuNoticeEnd;


    /**
     * 社保减员月查询范围
     */
    @ApiParam(value = N_SS_ATTRITION_MONTH_START, example = E_SS_ATTRITION_MONTH_START)
    private Date ssAttritionMonthStart;
    @ApiParam(value = N_SS_ATTRITION_MONTH_END, example = E_SS_ATTRITION_MONTH_END)
    private Date ssAttritionMonthEnd;


    /**
     * 公积金减员月查询范围
     */
    @ApiParam(value = N_PF_ATTRITION_MONTH_START, example = E_PF_ATTRITION_MONTH_START)
    private Date pfAttritionMonthStart;
    @ApiParam(value = N_PF_ATTRITION_MONTH_END, example = E_PF_ATTRITION_MONTH_END)
    private Date pfAttritionMonthEnd;


    @ApiParam(value = N_SURPLUS_YEAR_HOLIDAY, example = E_SURPLUS_YEAR_HOLIDAY)
    private Integer surplusYearHoliday;

    @ApiParam(value = N_SURPLUS_BREAK_OFF, example = E_SURPLUS_BREAK_OFF)
    private Integer surplusBreakOff;

    @ApiParam(value = N_DIRECTLY_UNDER_NUMBER, example = E_DIRECTLY_UNDER_NUMBER)
    private Integer directlyUnderNumber;

    @ApiParam(value = N_CHANGE_STATUS, example = E_CHANGE_STATUS, allowableValues = EmpChangeStatus.VALUES_STR)
    private Integer changeStatus;

    /**
     * 创建时间查询范围
     */
    @ApiParam(value = N_GMT_CREATE_START, example = E_GMT_CREATE_START)
    private Date gmtCreateStart;
    @ApiParam(value = N_GMT_CREATE_END, example = E_GMT_CREATE_END)
    private Date gmtCreateEnd;


    @ApiParam(value = N_CREATE_USER_ID, example = E_CREATE_USER_ID)
    @Length(max = 32)
    private String createUserId;

    /**
     * 修改时间查询范围
     */
    @ApiParam(value = N_GMT_MODIFIED_START, example = E_GMT_MODIFIED_START)
    private Date gmtModifiedStart;
    @ApiParam(value = N_GMT_MODIFIED_END, example = E_GMT_MODIFIED_END)
    private Date gmtModifiedEnd;


    @ApiParam(value = N_MODIFIED_USER_ID, example = E_MODIFIED_USER_ID)
    @Length(max = 32)
    private String modifiedUserId;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpChangesQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

